package com.heyqing.topic.MyQueue_0232;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

/**
 * ClassName:MyQueue
 * Package:com.heyqing.topic.MyQueue_0232
 * Description:
 *
 * @Date:2024/9/24
 * @Author:Heyqing
 */
public class MyQueue {

    private Stack<Integer> myQueue;
    private Stack<Integer> myQueuePop;

    public MyQueue() {
        myQueue = new Stack<>();
        myQueuePop = new Stack<>();
    }

    public void push(int x) {
        myQueue.push(x);
    }

    public int pop() {
        //将myQueue先转入myQueuePop，pop出myQueuePop栈顶元素
        while (!myQueue.isEmpty()) {
            myQueuePop.push(myQueue.pop());
        }
        Integer pop = myQueuePop.pop();
        //再将myQueuePop转入myQueue
        while (!myQueuePop.isEmpty()) {
            myQueue.push(myQueuePop.pop());
        }
        return pop;
    }

    public int peek() {
        while (!myQueue.isEmpty()) {
            myQueuePop.push(myQueue.pop());
        }
        Integer peek = myQueuePop.peek();
        while (!myQueuePop.isEmpty()) {
            myQueue.push(myQueuePop.pop());
        }
        return peek;
    }

    public boolean empty() {
        return myQueue.isEmpty();
    }
}
